/* Copyright (c) 2004-2008, Andriy Nikolov
 * All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.processmining.email;

import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.VerticalFlowLayout;
import java.awt.event.*;

/**
 * <p>A dialog to set the options used to build the task-person diagram</p>
 *
 * @author Andriy Nikolov
 * @version 1.0
 */
public class TaskPersonTableOptionsDialog
    extends JDialog {
  TaskPersonDiagramProducer producer;
  JPanel panel1 = new JPanel();
  BorderLayout borderLayout1 = new BorderLayout();
  BorderLayout borderLayout2 = new BorderLayout();
  JPanel jPanelOptions = new JPanel();
  VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
  JPanel jPanelButtons = new JPanel();
  JButton jButtonOK = new JButton();
  JButton jButtonCancel = new JButton();
  JCheckBox jCheckBoxMaximalArcsOnly = new JCheckBox();
  JCheckBox jCheckBoxOriginatorsOnly = new JCheckBox();
  boolean ok;

  public TaskPersonTableOptionsDialog(Frame owner, TaskPersonDiagramProducer producer, String title, boolean modal) {
    super(owner, title, modal);
    this.producer = producer;
    try {
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      jbInit();
      pack();
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }

  public TaskPersonTableOptionsDialog(Frame owner) {
    this(owner, null, "Task-person diagram options", false);
  }

  public TaskPersonTableOptionsDialog() {
    this(new Frame(), null, "Task-person diagram options", false);
  }

  private void jbInit() throws Exception {
    panel1.setLayout(borderLayout2);
    jPanelOptions.setLayout(verticalFlowLayout1);
    jPanelOptions.setBorder(BorderFactory.createEtchedBorder());
//    jButtonOK.setPreferredSize(new Dimension(73, 27));
    jButtonOK.setText("OK");
    jButtonOK.addActionListener(new
        TaskPersonTableOptionsDialog_jButtonOK_actionAdapter(this));
    jButtonCancel.setActionCommand("Cancel");
    jButtonCancel.setText("Cancel");
    jButtonCancel.addActionListener(new
        TaskPersonTableOptionsDialog_jButtonCancel_actionAdapter(this));
    jCheckBoxMaximalArcsOnly.setToolTipText(
        "Show only the most popular tasks for each person");
    jCheckBoxMaximalArcsOnly.setHorizontalAlignment(SwingConstants.LEFT);
    jCheckBoxMaximalArcsOnly.setText(
        "Show only the most popular tasks for each person");
    jCheckBoxOriginatorsOnly.setToolTipText("Include only the originators of events");
    jCheckBoxOriginatorsOnly.setText("Include only the originators of events");
    jCheckBoxOriginatorsOnly.setHorizontalAlignment(SwingConstants.LEFT);
    jPanelButtons.setBorder(BorderFactory.createEtchedBorder());
    panel1.add(jPanelOptions, java.awt.BorderLayout.CENTER);
    jPanelOptions.add(jCheckBoxMaximalArcsOnly);
    jPanelOptions.add(jCheckBoxOriginatorsOnly);
    this.getContentPane().add(panel1, java.awt.BorderLayout.CENTER);
    panel1.add(jPanelButtons, java.awt.BorderLayout.SOUTH);
    jPanelButtons.add(jButtonOK);
    jPanelButtons.add(jButtonCancel);
    ok = false;
  }

  public void jButtonOK_actionPerformed(ActionEvent e) {
    if(producer!=null) {
      producer.setShowOnlyMaximalArcs(jCheckBoxMaximalArcsOnly.isSelected());
      producer.setShowOnlyOriginators(jCheckBoxOriginatorsOnly.isSelected());
    }
    ok = true;
    processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  }

  public boolean isOK() {
    return ok;
  }

  public void jButtonCancel_actionPerformed(ActionEvent e) {
    ok = false;
    processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  }
}

class TaskPersonTableOptionsDialog_jButtonCancel_actionAdapter
    implements ActionListener {
  private TaskPersonTableOptionsDialog adaptee;
  TaskPersonTableOptionsDialog_jButtonCancel_actionAdapter(
      TaskPersonTableOptionsDialog adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonCancel_actionPerformed(e);
  }
}

class TaskPersonTableOptionsDialog_jButtonOK_actionAdapter
    implements ActionListener {
  private TaskPersonTableOptionsDialog adaptee;
  TaskPersonTableOptionsDialog_jButtonOK_actionAdapter(
      TaskPersonTableOptionsDialog adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonOK_actionPerformed(e);
  }
}
